<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "com.classes.Notification, java.util.TreeMap, java.util.ArrayList, org.owasp.encoder.Encode" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%

TreeMap<String, String> search = (TreeMap<String, String>) request.getAttribute("search");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<title>MAYBANK</title>
</head>

<body>

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


<div class="row-fluid page">
	<div class="span12">

		<jsp:include page="/jsp/map/include/notification-tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("notification") %>' />
		</jsp:include>
		
		
		<form name="search_form" method="post" action="<%= request.getContextPath() + "/Notification.do?dispatch=init" %>">
			<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
			<div class="row-fluid form-horizontal search">
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Reference No.</label>
						<div class="controls">
							<%
							String html = "";
							if(search.containsKey("case_id") && search.get("case_id").length() > 0){
								html = search.get("case_id");
							}
							%>
							<input type="text" id="case_id" name="case_id" value="<%= html %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Registration Name</label>
						<div class="controls">
							<%
							html = "";
							if(search.containsKey("merchant_name") && search.get("merchant_name").length() > 0){
								html = search.get("merchant_name");
							}
							%>
							<input type="text" id="merchant_name" name="merchant_name" value="<%= html %>" />
						</div>
					</div>
				</div>
				
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Application Type</label>
						<div class="controls">
							<select id="application_type" name="application_type">
							<% 
								html = "<option value=\"\"></option>"
									+ "<option value=\"New Application\">New Application</option>"
									+ "<option value=\"Extend Facility\">Extend Facility</option>"
									+ "<option value=\"e-Commerce/M2u\">e-Commerce/M2u</option>";
								
								if(search.containsKey("application_type") && search.get("application_type").length() > 0){
									html = html.replace("value=\"" + search.get("application_type") + "\"", "value=\"" + search.get("application_type") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					
					<div class="control-group">
						<label class="control-label">To Do Status</label>
						<div class="controls">
							<select id="status" name="status">
							<% 
								html = "<option value=\"Active\">Active</option>"
									+ "<option value=\"Done\">Done</option>";
								
								if(search.containsKey("status") && search.get("status").length() > 0){
									html = html.replace("value=\"" + search.get("status") + "\"", "value=\"" + search.get("status") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					
					<div class="control-group">
						<label class="control-label">From Date</label>
						<div class="controls">
							<%
							html = (String) request.getAttribute("fromDate");
							if(search.containsKey("from_date")){
								html = search.get("from_date");
							}
							%>
							<input type="text" id="from_date" name="from_date" placeholder="yyyy-mm-dd" value="<%= html %>" />
						</div>
					</div>
					
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span12 btn-control search">
					<button id="search_submit" name="search_submit" type="submit" class="btn">Search</button>
					<button id="search_clear" name="search_clear" type="submit" class="btn">Clear</button>
				</div>
			</div>
		</form>
		
		<table class="tblDetails"><thead>
			<tr>
				<th>Reference No.</th>
				<th>Registration No.</th>
				<th>Registration Name</th>
				<th>Application Type</th>
				<th>Last Action</th>
				<th>By</th>
				<th>Assigned Date</th>
			</tr>
		</thead><tbody>
		<%
			int n = 0;
			for(Notification c : (ArrayList<Notification>) request.getAttribute("nArr")){
				String case_url = request.getContextPath() + "/NewApp.do?dispatch=init&m_id=" + EncryptionHelper.encryptEncodeURL(c.getInfo("merchant_id")) + "&c_id=" + EncryptionHelper.encryptEncodeURL(c.getInfo("case_id"));
				
				html = "<tr class=" + (n % 2 > 0 ? "alt" : "even") + ">"
				+ "	<td><a href=\"" + case_url + "\">" + Encode.forHtml(c.getInfo("case_reference_no")) + "</a></td>"
				+ "	<td>" + Encode.forHtml(c.getInfo("registered_no")) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getInfo("registered_name")) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getInfo("app_type")) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getInfo("type")) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getInfo("created_by")) + "</td>"
				+ "	<td>" + Notification.formatCreatedDate("dd/MM/yyyy HH:mm", Long.parseLong(c.getInfo("created_date"))) + "</td>"
				+ "</tr>";
				
				out.println(html);
				++n;
			}
		%>
		</tbody></table>
		
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->


</body>
</html>